package org.apache.flink.runtime.resourceconsumer;

import static org.apache.flink.util.Preconditions.checkNotNull;

import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;

import org.apache.flink.api.common.ConsumerID;

/**
 * The report of currently allocated slots from a given TaskExecutor by a JobMaster. This report is
 * sent periodically to the TaskExecutor in order to reconcile the internal state of slot
 * allocations.
 */
public class AllocatedSlotReport implements Serializable {

    private static final long serialVersionUID = 1L;

    private final ConsumerID jobId;

    /** The allocated slots in slot pool. */
    private final Collection<AllocatedSlotInfo> allocatedSlotInfos;

    public AllocatedSlotReport(ConsumerID jobId, Collection<AllocatedSlotInfo> allocatedSlotInfos) {
        this.jobId = checkNotNull(jobId);
        this.allocatedSlotInfos = checkNotNull(allocatedSlotInfos);
    }

    public ConsumerID getJobId() {
        return jobId;
    }

    public Collection<AllocatedSlotInfo> getAllocatedSlotInfos() {
        return Collections.unmodifiableCollection(allocatedSlotInfos);
    }

    @Override
    public String toString() {
        return "AllocatedSlotReport{"
                + "jobId="
                + jobId
                + ", allocatedSlotInfos="
                + allocatedSlotInfos
                + '}';
    }
}
